package 力扣;

/**
 * @author yyq
 * @create 2022-04-11 14:15
 */
public class leetcode404 {
    public static void main(String[] args) {

    }
    public int sumOfLeftLeaves(TreeNode root) {
        if(root==null) return 0;
        int[] sum=new int[1];
        preOrder(sum,root);
        return sum[0];
    }

    private void preOrder(int[] sum, TreeNode root) {
        if(root.left!=null&&root.left.left==null&&root.left.right==null){
            sum[0] = sum[0] + root.left.val;
        }
        if(root.left!=null) preOrder(sum,root.left);
        if(root.right!=null) preOrder(sum,root.right);
    }
}
